package com.example.day0225

import android.icu.util.Calendar
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize

import androidx.compose.material3.MaterialTheme

import androidx.compose.material3.Surface

import androidx.compose.ui.Modifier
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable

import androidx.navigation.compose.rememberNavController
import com.example.day0221.views.MainPage
import com.example.day0225.ui.theme.Day0225Theme

import com.example.lib_base.RoutePath
import com.example.lib_http.Const
import com.example.sign.view.SignCommitPage
import com.tencent.mmkv.MMKV
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.time.LocalTime


@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //enableEdgeToEdge()
        setContent {
            requestPermissions(
                arrayOf(
                    android.Manifest.permission.ACCESS_COARSE_LOCATION,
                    android.Manifest.permission.ACCESS_FINE_LOCATION,
                    android.Manifest.permission.READ_EXTERNAL_STORAGE,
                    android.Manifest.permission.WRITE_EXTERNAL_STORAGE
                ), 102
            )
            Day0225Theme {
                Surface (modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background){



                    //Demon01()
                    //Demon02()
                    //Demon03()
                    //Demon04()
                    //Demon05()
                    //Demon06()
                    //MainPage()
                    //AppsPage()
                    var startPage = RoutePath.WELCOME
                    val mmkv = MMKV.defaultMMKV()
                    val navController = rememberNavController()
                    //通过mmkv去读取是否进入过app
                    val isIn = mmkv.decodeBool(Const.PARAM_IS_IN, false)
                    if (isIn) {
                        //如果进入过app,则直接跳转到主页面
                        startPage = RoutePath.MAIN
                    } else {
                        //如果首次进入app,则进入欢迎页,然后倒计时5秒后,再次进入首页
                        lifecycleScope.launch {
                            //延迟5秒
                            async { delay(5000) }.await()
                            //跳转至首页
                            navController.navigate(RoutePath.MAIN)
                            //保存是否进入过
                            mmkv.encode(Const.PARAM_IS_IN, true)
                        }
                    }

                    NavHost(navController = navController, startDestination = startPage, builder = {
                        composable(RoutePath.WELCOME) { WelcomePage() }
                        composable(RoutePath.MAIN) { MainPage() }
                    })


                }
            }
        }
    }
}
